"""
Case Type   : cm_install
Case Name   : cm_install显示帮助信息
Create At   : 2022/11/15
Owner       : @daiguatutu
Description :
    1.cm_install显示帮助信息
Expect      :
    1.执行成功，显示帮助信息正确且与实际一致
History     :
    modified by @ningyali at 2025-4-15:优化用例
"""
import os
import unittest

from testcase.utils.Common import Common
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class CMInstallCase(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_user = Node('PrimaryDbUser')
        self.common = Common()
        self.cm_tool_path = os.path.join(
            os.path.dirname(macro.DB_SCRIPT_PATH), 'tool', 'cm_tool')

    def test_install(self):
        text = '-----step1:cm_install显示帮助信息 expect:成功-----'
        self.log.info(text)
        help_cmd = f"cd {self.cm_tool_path};./cm_install -?"
        help_res = self.common.get_sh_result(self.pri_user, help_cmd)
        expect_msg = ['cm_install is a utility to deploy CM tool '
                      'to openGauss database cluster',
                      'cm_install -? | --help',
                      'cm_install -X XMLFILE [-e envFile] --cmpkg=cmpkgPath',
                      '-X                                 '
                      'Path of the XML configuration file',
                      '-e                                 Path of env file.',
                      'Default value "~/.bashrc".',
                      '--cmpkg                            Path of CM pacakage.',
                      '-?, --help                         '
                      'Show help information for this',
                      'utility, and exit the command line mode.']
        for content in expect_msg:
            self.log.info(f'check [{content}] in help_res')
            self.assertIn(content, help_res, f'执行失败:{text}')

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
